package com.baizhi.service.impl;

import com.baizhi.dto.Result;
import com.baizhi.entity.Shop;
import com.baizhi.mapper.ShopMapper;
import com.baizhi.service.IShopService;
import com.baizhi.utils.CacheClient;
import com.baizhi.utils.RedisConstants;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gange
 * @since 2023-04-06
 */
@Service
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements IShopService {
    @Resource
    private CacheClient cacheClient;


    @Override
    public Result queryById(Long id) {
       Shop shop = cacheClient.queryWithMutex(id, RedisConstants.CACHE_SHOP_KEY,
                this::getById
        ,RedisConstants.CACHE_SHOP_TTL, TimeUnit.MINUTES);

        return Result.ok(shop);
    }
}
